package com.example.shop.service;

import com.example.shop.entity.User;
import com.example.shop.mapper.UserMapper;
import com.example.shop.utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImp  implements UserService {

    @Autowired
    UserMapper userMapper;
    public User finduser(User user) {
        User user1 = userMapper.find(user);
        System.out.println("-------------------------------user1");
        System.out.println(user1);
        String token = JwtUtil.createToken(user1.getUsername(),user1.getPassword());
        user1.setToken(token);
        return user1;
    }

    public int update(User user) {
        return userMapper.update(user);
    }

    public int delete(int id) {
        return userMapper.delete(id);
    }


    public List<User> findByMul(Integer id, String username, String tel, String email) {
        return userMapper.findByMul(id,username,tel,email);
    }

    public int InsertUser(User user) {
        return userMapper.InsertUser(user);
    }

    @Override
    public List<User> findPage(int pageSize, int pageNum) {
        return userMapper.findPage(pageSize,pageNum);
    }

    @Override
    public int totalUser() {
        return userMapper.totalUser();
    }

    @Override
    public User findByUsername(String username) {
        return userMapper.findByUsername(username);
    }

    @Override
    public int SetTxUrl(String username, String finalPath) {
        return userMapper.SetTxUrl(username,finalPath);
    }
}

